var canvs = document.getElementById('chess');
var ctx = canvs.getContext('2d');

var Options={
	self:0,
	0:100,
	1:200,
	2:300,
	3:400,
	4:500,
	noZhe:100,
	lianXu:100
}
/**
 * 画棋盘
 */
function drawPan(ctx) {
    ctx.strokeStyle = "#888";
    for (var i = 0; i < 15; i++) {
        var y = 15 + 30 * i, x1 = 15, x2 = 435;
        ctx.moveTo(x1, y);
        ctx.lineTo(x2, y);
        ctx.stroke();
        ctx.beginPath();
        ctx.textBaseline='middle';
        ctx.fillText(i,0,y);
        ctx.closePath();
    }
    for (var i = 0; i < 15; i++) {
        var y = 15 + 30 * i, x1 = 15, x2 = 435;
        ctx.moveTo(y, x1);
        ctx.lineTo(y, x2);
        ctx.stroke();
        ctx.beginPath();
        ctx.textAlign='center';
        ctx.fillText(i,y,5);
        ctx.closePath();
    }
}
drawPan(ctx);
/**
 * 画棋子
 * @param x
 * @param y
 * @param white
 */
function drawZi(x,y,white,red) {
	x= x*30+15;
	y= y*30+15;

    ctx.beginPath();
    ctx.arc(x, y, 12, 0, 2 * Math.PI);
    ctx.closePath();
    var cgt = ctx.createRadialGradient(x,y,12,x,y,0);
     if(red){
         if(white){
              cgt.addColorStop(0,'#333');
         }else{
              cgt.addColorStop(0,'#aaa');
         }
        // cgt.addColorStop(0,'#f00');
        cgt.addColorStop(1,'#ff0');
    }else if(!white){
        cgt.addColorStop(0,'#333');
        cgt.addColorStop(1,'#ccc');
    }else{
        cgt.addColorStop(0,'#aaa');
        cgt.addColorStop(1,'#fff');
    }


    ctx.fillStyle=cgt;
    ctx.fill();
}
var G = {};
(function (w) {
	var fangAns = [];
	var points = [];
	var pointOne = [];
	function getPoint(x,y) {
		if(x<0||y<0||x>14||y>14)return null;
		return points[x][y];
	}
	class Point{
		constructor(x,y){
			this.x= x;
			this.y= y;
			this.fangAns = [];
			this.color = 4;//all;
		}
		add(fangan){
			this.fangAns.push(fangan);
		}
		calculateScore(color){
			//方案自身的评分
			var score=this.fangAns.map(fangAn=>fangAn.getScore(color));
		}
	}
	var  setStartEnd=[function (x,y) {//竖
		return [
			getPoint(x,y-1),getPoint(x,y+5)
		]
	},function (x,y) {//竖横斜反
		return [
			getPoint(x-1,y),getPoint(x+5,y)
		]
	},function (x,y) {
		return [
			getPoint(x-1,y-1),getPoint(x+5,y+5)
		]
	},function (x,y) {
		return [
			getPoint(x+1,y-1),getPoint(x-5,y+5)
		]
	}]
	class FangAn{
		constructor(type,x,y){
			this.points = [];
			this.color = 4;//all
			this.step = 0;
			this.type = type;//竖横斜反
			var se = setStartEnd[type-1](x,y);
			this.start = se[0];
			this.end = se[1];
		}
		add(x,y){
			
			var point = getPoint(x,y);
			this.points.push(point);
			point.add(this);
		}
		getScore(c){
			if(this.color==5)return 0;//无效的方案不记分
			//有无遮挡
			if(this.start.color==4&&this.end.color==4)
			//颜色是否相同，自己的和他人的
			if(this.color==c)
			//是否连续
			if(this.)
			//完成情况
		}
	}
	var point=null;
	for(var i =0;i<15;i++){
			points[i]=[];
		for(var j=0;j<15;j++){
			point=
			points[i][j]=new Point(i,j);
			pointOne.push(point);
		}
	}
	var temp = null;
	for(var i=0;i<15;i++){
		for(var j=0;j<11;j++){
			temp= new FangAn(1,i,j);
			for(var k=0;k<5;k++){
				temp.add(i,j+k);
			}
			fangAns.push(temp);
		}
	}
	for(var i=0;i<15;i++){
		for(var j=0;j<11;j++){
			temp= new FangAn(2,i,j);
			for(var k=0;k<5;k++){
				temp.add(j+k,i);
			}
			fangAns.push(temp);
		}
	}
	for(var i=0;i<11;i++){
		for(var j=0;j<11;j++){
			temp= new FangAn(3,i,j);
			for(var k=0;k<5;k++){
				temp.add(i+k,j+k);
			}
			fangAns.push(temp);
		}
	}
	for(var i=14;i>3;i--){
		for(var j=0;j<11;j++){
			temp= new FangAn(4,i,j);
			for(var k=0;k<5;k++){
				temp.add(i-k,j+k);
			}
			fangAns.push(temp);
		}
	}

	w.G.points = points;
	w.G.fangAns = fangAns;
	w.G.pointOne = pointOne;


})(window);

G.pointOne.sort(function (a,b) {
	
});
(function (w) {
	w.G.color = {
		black:1,
		all:4,
		white:2,
		none:5
	}
	class QiShou{

		constructor(color){
			this.color = color;
		}
		luozi(){

		}

	}
	w.QiShou = QiShou;
	
})(window);
var blackQiShou = new QiShou(G.color.black);
var whiteQiShou = new QiShou(G.color.white);
	

// emit('start-game')
whiteQiShou.luozi();



	

// canvs.onclick=handler.nomal;